package com.raycloud.action;

import java.util.Map;

import org.apache.log4j.Logger;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;
import com.raycloud.domain.User;
import com.raycloud.manager.UserMgr;

public class LoginAction extends ActionSupport implements SessionAware{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static final Logger logger = Logger.getLogger(LoginAction.class);
	
	private String email;
	private String password;
	private String userId;
	
	private UserMgr userMgr;
	
	private Map<String, Object> session;

	public String execute() throws Exception {
		logger.debug("email == " + email + " password == " + password);
		User user = userMgr.getUser(email, password);
		if(user == null) {
			return "login_fail";
		} else {
			session.put("user", user);
			userId = String.valueOf(user.getId());
		}
		return SUCCESS;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserMgr(UserMgr userMgr) {
		this.userMgr = userMgr;
	}

	public void setSession(Map<String, Object> session) {
		this.session = session;
	}
	
}
